import random
import datetime
money=5000
cart=[]
commodity=[
    ["手机", 1000],
    ["电脑", 4000],
    ["电视", 2000],
    ["耳机", 200],
    ["杯子", 100],
    ["滑板", 500],
    ["插座", 10],
    ["相机", 8000],
    ["纸巾", 1],
    ["啤酒", 5],
    ["烧鸡",688]
]
coupon=random.randint(0,10)
commodity[coupon][1]=0.8*commodity[coupon][1]
print("您抽到",commodity[coupon][0],"八折优惠，恭喜您！")
print("--------------欢迎来到购物系统--------------")
while True:
    for index,c in enumerate(commodity):
        print(index,c)
    num=input("请选择需要购买的商品编号(按Q或q退出购物)(按C或c进入购物车)：")
    if num=="q" or num=="Q":
        print("退出购物")
        sum=0
        for x in cart:
            sum+=x[1]
        for io in range(0,11):
            count=cart.count(commodity[io])
            if count>0:
                print(commodity[io],"数量为：",count)
            else:
                continue
        print("您的余额为：",money,"一共消费：",sum,"购物日期：",datetime.datetime.today())
        break
    elif num=="c" or num=="C":
        print("----------购物车----------")
        for x1,x2 in enumerate(cart):
            print(x1,x2)
        t=input("请输入退货编号(按q或Q退出购物车)：")
        if t=="Q" or t=="q":
            continue
        elif t.isdigit():

            if    int(t)>len(cart):
                print("输入错误，退出购物车")
                continue
            else:
                money+=cart[int(t)][1]
                print("您退货",cart[int(t)][0],"X1，成功，您的余额增加",cart[int(t)][1],"元，您的余额为：",money)
                cart.pop(int(t))
        else:
            print("输入错误，退出购物车")
            continue
        input("按enter继续")
    elif num.isdigit():
        if int(num)>10:
            print("没有该商品!")
        else:
            if money>=commodity[int(num)][1]:
                cart.append(commodity[int(num)])
                money-=commodity[int(num)][1]
                print("购买成功，余额还有：",money)
                input("按enter继续")
            else:
                print("钱不够了,余额只有",money)
                input("按enter继续")
    else:
        print("输入错误，请重新输入")
        input("按enter继续")